package com.xidian.zhiancloud.controller.emergencyManagement;

import com.xidian.zhiancloud.controller.base.BaseController;
import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.model.Warehousing;
import com.xidian.zhiancloud.service.emergencyManagement.WarehousingService;
import com.xidian.zhiancloud.vo.emergencyManagement.WarehousingVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 应急管理 应急物资管理接口-入库
 */
@RestController
@RequestMapping("/Warehousing")
public class WarehousingController extends BaseController {
    @Autowired
    private WarehousingService warehousingService;

    /**
     * 增加入库记录
     *
     * @param warehousing 入库对象
     * @return 返回是否添加成功
     */
    @PostMapping("/add")
    public ResultDTO<Boolean> add(Warehousing warehousing) {
        warehousing.setCreateTime(new Date(System.currentTimeMillis()));
        warehousing.setCreatorId(getSessionUserid());
        warehousing.setCompanyId(getSessionUserCompanyId());
        Boolean res = warehousingService.add(warehousing);
        return ResultDTO.successOf(res, GeneralResponseEnums.SUCCESS);
    }

    /**
     * 获取入库记录
     * @param id 入库id
     * @return 入库对象
     */
    @GetMapping("/getWarehousing")
    public  ResultDTO<List<WarehousingVO>> getWarehousing(@RequestParam("id") Long id){
        return ResultDTO.successOf(warehousingService.getWarehousing(id),GeneralResponseEnums.SUCCESS);
    }

}
